﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace GiaoDien
{
    public partial class SanPham : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["GioHang"] == null)
                lblSPGH.Text = "0";
            else
            {
                List<ServiceKD.SanPham> lst = (List<ServiceKD.SanPham>)Session["GioHang"];
                lblSPGH.Text = lst.Count + " ";
            }

            if (Session["DangNhap"] != null)
            {
                ServiceKD.KhachHang kh = (ServiceKD.KhachHang)Session["DangNhap"];
                lblPhanQuyen.Text = kh.maPhanQuyen + "";
            }

            ServiceKD.ServiceSoapClient proxy1 = new GiaoDien.ServiceKD.ServiceSoapClient("ServiceSoap");
            ServiceKD.DanhMucSanPham[] dsdm = proxy1.layDanhMuc();
            String[] tendm = new String[dsdm.Length];
            int[] madm = new int[dsdm.Length];


            int MaDanhMuc = 0;
            if (Request.QueryString["MaDanhMuc"] != null)
                MaDanhMuc = Int32.Parse(Request.QueryString["MaDanhMuc"]);
            ServiceKD.SanPham[] dssp = proxy1.laySanPham(MaDanhMuc);

            for (int i = 0; i < dsdm.Length; i++)
            {
                tendm[i] = dsdm[i].tenDanhMuc;
                madm[i] = dsdm[i].maDanhMuc;
            }
            Session["TenDanhMuc"] = tendm;
            Session["MaDanhMuc"] = madm;

            CollectionPager2.PageSize = 9;
            CollectionPager2.DataSource = dssp;
            CollectionPager2.BindToControl = DTLSanPham;
            DTLSanPham.DataSource = CollectionPager2.DataSourcePaged;
            DTLSanPham.DataBind();

        }

        protected void lbtnDangXuat_Click(object sender, EventArgs e)
        {
            Session["DangNhap"] = null;
            Response.Redirect("DangNhap.aspx");
        }


        
    }
}
